package com.jinkeen.xiaxie

import android.util.Log
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.jinkeen.xiaxie.base.MyApplication
import com.jinkeen.xiaxie.base.log
import com.jinkeen.xiaxie.workmanager.UploadWorker
import junit.framework.TestListener
import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {

    companion object {
        const val TAG = "Test----"
    }

    @Test
    fun addition_isCorrect() {
        val worker = OneTimeWorkRequestBuilder<UploadWorker>().build()
        WorkManager.getInstance().enqueue(worker)
    }


    interface Api {
        fun a()
        fun b()
    }

    class ApiWrapper(val api: Api) : Api by api {
        override fun a() {
            log("aaaaa")
        }

        override fun b() {
            log("bbbbb")
        }
    }


    fun log(str: String) {
        Log.e(TAG, str)
    }


    @Test
    fun main() {
        val exampleUnitTest: ExampleUnitTest = ExampleUnitTest()

        test1 {
            println("hello test1")
        }

        test2 {
            "hello test2"
        }

        test3 { x, y ->
            x + y
        }

        val result = test4 { x, y ->
            x * y
        }

        test3 { x, y ->
            x - y
        }

        println("result test4==>$result")
        exampleUnitTest.setTest(object : OnTest {
            override fun onStart(str: String) {
                println(str)
            }

        })
        exampleUnitTest.onTest?.onStart("aaa")

        exampleUnitTest.onRead {
            println(it)
        }
    }

    private fun test5(x: Int, y: Int) {
        println(x + y)
    }

    private fun test1(block: () -> Unit) {
        block()
    }

    private fun test2(block: () -> String) {
        val value = block()
        println("block return value====>$value")
    }

    private fun test3(block: (x: Int, y: Int) -> Int) {
        val result = block(1, 3)
        println("block cal value====>$result")
    }

    private fun test4(block: (x: Int, y: Int) -> Int) {
        val result = block(1, 3)
        println("block cal value ====>$result")
    }


    //回调函数
    interface OnTest {
        fun onStart(str: String)
    }

    var onTest: OnTest? = null

    private fun setTest(onTest: OnTest) {
        this.onTest = onTest
    }

    private fun onRead(block: (String) -> Unit) {
        block("123")
    }


}